using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TitanX;
using System;
//特效
public class AddEffect: SingletonGetMono<AddEffect>{

    public Effect[] effects;

    public List<GameObject> list=new List<GameObject>();

    public Dictionary<string,GameObject> effectsDic=new Dictionary<string,GameObject>();


    private void Awake(){

        foreach(Effect eff in effects){

            effectsDic.Add(eff.name,eff.prefab);
        }




    }



    public void ShowEffect(string name,Vector3 v3,float time){

        GameObject gm= OutPool(name);
        gm.SetActive(true);
        gm.transform.position=v3;



    }

    public void HideEffect(GameObject gm){
        gm.SetActive(false);
    }

    private void initPool(){
         foreach(Effect eff in effects){
            GameObject gmpre= Instantiate(eff.prefab);
            gmpre.transform.parent = gameObject.transform;
            gmpre.name = eff.name;
            gmpre.SetActive(false);
            list.Add(gmpre);
        }
    }



    private GameObject OutPool(string name){

        foreach(GameObject gm in list){
            if(gm.name.Equals(name)&& !gm.activeSelf){
                return gm;
            }

        }

        GameObject gmpre= Instantiate(effectsDic[name]);
        gmpre.transform.parent = gameObject.transform;
        gmpre.name = name;
        gmpre.SetActive(false);
        list.Add(gmpre);
        return gmpre;
    }





}


public class Effect{
    public string name;
    public GameObject prefab;


}